package cm367;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;

@ManagedBean
@ApplicationScoped
public class UserService {
	
	private List<User> users = new ArrayList<User>();
	
	public UserService() throws ParseException {
		users.add(new User("John", "john@gmail.com", "Admin", "123456", "Mr.", "55555555"));
		users.add(new User("Mary", "mary@gmail.com", "user", "123456", "Miss","55555555"));
	}
	
	public boolean validateUser(String name, String password){
		for(User user: users){
			if (user.getName().equals(name) && user.getPassword().equals(password)){
				return true;
			}
		}
		return false;
	}
	
	public User findUserByName(String name){
		for(User user: users){
			if (user.getName().equals(name)){
				return user;
			}
		}
		return null;
	}

	public List<User> getUsers() {
		return users;
	}

	public void setUsers(List<User> users) {
		this.users = users;
	}
	
	
}
